﻿<template>
	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
				<el-form ref="elForm" :model="dataForm" size="medium" label-width="100px" label-position="right" :disabled="!!isDetail" :rules="rules">
					<el-col :span="12" >
						<el-form-item label="项目编号" prop="enCode">
							<el-input v-model="dataForm.enCode" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="项目名称" prop="fullName">
							<el-input v-model="dataForm.fullName" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="项目类型" prop="itemType">
							<el-select v-model="dataForm.itemType" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in itemTypeOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="项目金额" prop="amount">
							<el-input-number v-model="dataForm.amount" placeholder="数字文本" required :precision="2"  :step="100" >
							</el-input-number>元
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="签订时间" prop="signingTime">
							<el-date-picker v-model="dataForm.signingTime" placeholder="请选择" clearable required :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="项目阶段" prop="stage">
							<el-select v-model="dataForm.stage" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in stageOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="开始时间" prop="startTime">
							<el-date-picker v-model="dataForm.startTime" placeholder="请选择" clearable required :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="结束时间" prop="endTime">
							<el-date-picker v-model="dataForm.endTime" placeholder="请选择" clearable required :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="项目工期" prop="timeLimit">
							<el-input-number v-model="dataForm.timeLimit" placeholder="数字文本" required :step="1" controls-position="right" >
							</el-input-number>天
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="完成进度" prop="schedule">
							<el-input-number v-model="dataForm.schedule" placeholder="数字文本" required :step="1" controls-position="right" >
							</el-input-number>%
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="项目经理" prop="desPerson">
							<user-select v-model="dataForm.desPerson" placeholder="请选择" required >
							</user-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="参与人员" prop="managerIds">
							<user-select v-model="dataForm.managerIds" placeholder="请选择" required multiple >
							</user-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="项目状态" prop="state">
							<el-select v-model="dataForm.state" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in stateOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="客户名称" prop="customer">
							<el-select v-model="dataForm.customer" placeholder="请选择" clearable required :style='{"width":"100%"}' filterable >
								<el-option v-for="(item, index) in customerOptions" :key="index" :label="item.Name" :value="item.Id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="项目内容" prop="proContent">
							<el-input v-model="dataForm.proContent" placeholder="请输入" required show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="附件" prop="appendix">
							<JNPF-UploadFz v-model="dataForm.appendix" :fileSize="20" sizeUnit="MB" :limit="9" buttonText="点击上传" >
							</JNPF-UploadFz>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="备注" prop="remark">
							<el-input v-model="dataForm.remark" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建用户" prop="creatorUserId">
							<el-input v-model="dataForm.creatorUserId" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建时间" prop="creatorTime">
							<el-input v-model="dataForm.creatorTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="修改用户" prop="lastModifyUserId">
							<el-input v-model="dataForm.lastModifyUserId" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="修改时间" prop="lastModifyTime">
							<el-input v-model="dataForm.lastModifyTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
		</div>
	</transition>
</template>
<script>
	import request from '@/utils/request'
	import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
	import { previewDataInterface } from '@/api/systemData/dataInterface'
	export default {
		components: {},
		props: [],
		data() {
			return {
				loading: false,
				visible: false,
				isDetail: false,
				dataForm: {
					enCode:undefined,
					fullName:undefined,
					itemType:undefined,
					amount:0,
					signingTime:undefined,
					stage:undefined,
					startTime:undefined,
					endTime:undefined,
					timeLimit:0,
					schedule:0,
					desPerson:undefined,
					managerIds:undefined,
					state:undefined,
					customer:undefined,
					proContent:undefined,
					appendix:[],
					remark:undefined,
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					fullName:[
						{
							required:true,
							message:'请输入项目名称',
							trigger:'blur'
						},
					],
					itemType:[
						{
							required:true,
							message:'请输入项目类型',
							trigger:'change'
						},
					],
					amount:[
						{
							required:true,
							message:'请输入项目金额',
							trigger:["blur","change"]
						},
					],
					signingTime:[
						{
							required:true,
							message:'请输入签订时间',
							trigger:'change'
						},
					],
					stage:[
						{
							required:true,
							message:'请输入项目阶段',
							trigger:'change'
						},
					],
					startTime:[
						{
							required:true,
							message:'请输入开始时间',
							trigger:'change'
						},
					],
					endTime:[
						{
							required:true,
							message:'请输入结束时间',
							trigger:'change'
						},
					],
					timeLimit:[
						{
							required:true,
							message:'请输入项目工期',
							trigger:["blur","change"]
						},
					],
					schedule:[
						{
							required:true,
							message:'请输入完成进度',
							trigger:["blur","change"]
						},
					],
					desPerson:[
						{
							required:true,
							message:'请输入项目经理',
							trigger:'change'
						},
					],
					managerIds:[
						{
							required:true,
							message:'请输入参与人员',
							trigger:'change'
						},
					],
					state:[
						{
							required:true,
							message:'请输入项目状态',
							trigger:'change'
						},
					],
					customer:[
						{
							required:true,
							message:'请输入客户名称',
							trigger:'change'
						},
					],
					proContent:[
						{
							required:true,
							message:'请输入项目内容',
							trigger:'blur'
						},
					],
				},
				itemTypeOptions : [],
				stageOptions : [],
				stateOptions : [],
				customerOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getitemTypeOptions();
			this.getstageOptions();
			this.getstateOptions();
			this.getcustomerOptions();
		},
		mounted() {
        },
		methods: {
			getitemTypeOptions(){
				getDictionaryDataSelector('0fd534ef4423481f8a3c2bfc87de8943').then(res => {
					this.itemTypeOptions = res.data.list
				});
			},
			getstageOptions(){
				getDictionaryDataSelector('90e5b20bd000435aad8cd4b669dccfec').then(res => {
					this.stageOptions = res.data.list
				});
			},
			getstateOptions(){
				getDictionaryDataSelector('2b32fa4cc6b340af80f55f046b0432e3').then(res => {
					this.stateOptions = res.data.list
				});
			},
			getcustomerOptions(){
				previewDataInterface('195029830188664069').then(res => {
					this.customerOptions = res.data
				});
			},
			goBack() {
                this.$emit('refresh')
            },
			init(id, isDetail) {
				this.dataForm.id = id || 0;
                this.visible = true;
                this.isDetail = isDetail || false;
				this.$nextTick(() => {
					this.$refs['elForm'].resetFields();
					if (this.dataForm.id) {
						request({
							url: '/api/SubDev/ZyOaProjectgantt/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
						})
					}
				})
			},
			dataFormSubmit() {
				this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                        if (!this.dataForm.id) {
                            request({
                                url: `/api/SubDev/ZyOaProjectgantt`,
                                method: 'post',
                                data: this.dataForm,
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false,
                                            this.$emit('refresh', true)
                                    }
                                })
                            })
                        } else {
                            request({
                                url: '/api/SubDev/ZyOaProjectgantt/' + this.dataForm.id,
                                method: 'PUT',
                                data: this.dataForm
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refresh', true)
                                    }
                                })
                            })
                        }
                    }
                })
			},
		}
	}
</script>
